package com.rank.ccms.service.model;

import com.rank.ccms.domain.model.RoleEntity;
import com.rank.ccms.domain.model.UserEntity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Project: Suggestion List
 * User: Octavian Rusu
 * Date: 05/24/2010
 */
public class User implements Serializable {

    private Long id;
    private String userName;
    private String firstName;
    private String lastName;
    private List<Role> roles = new ArrayList<Role>();

    public User(UserEntity userEntity) {
        this.id = userEntity.getId();
        this.userName = userEntity.getUserName();
        this.firstName = userEntity.getDetails().getFirstName();
        this.lastName = userEntity.getDetails().getLastName();        
        for(RoleEntity re:userEntity.getRoles()){
            addRole(new Role(re));
        }
    }

    public User(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public List<Role> getRoles() {
        return Collections.unmodifiableList(roles);
    }

    public void setRoles(List<Role> roles) {
        this.roles.clear();
        this.roles.addAll(roles);
    }

    public void addRole(Role role){
        this.roles.add(role);
    }
}
